﻿myApp.controller("lawyerfeeController", function ($scope, $http, $modal, $routeParams, authService, $location, $window) {
    document.title = "Penang Realty 世界地產 Legal Fee Calculator";
    $scope.$emit('newPageLoaded', { 'title': 'Penang Realty BUY OR RENT WITH US 世界地產 Legal Fee Calculator', 'description': 'Free online lawyer fee calculator. Try it now.' });
    $scope.calculate = function () {
        validation();
        if ($scope.warning.length > 0)
            return;
        else
            $scope.warning = null;

        $scope.snpLegalfee = 0;
        if ($scope.propertyPrice <= 150000){
            $scope.snpLegalfee = Math.max(0.01 * $scope.propertyPrice,300);
        }
        else if ($scope.propertyPrice <= 1000000){
            $scope.snpLegalfee = 150000 * 0.01 + ($scope.propertyPrice - 150000) * 0.007;
        }
        else if($scope.propertyPrice <= 3000000){
            $scope.snpLegalfee = 150000 * 0.01 + (850000) * 0.007 + (3000000 - $scope.propertyPrice) * 0.006;
        }
        else if ($scope.propertyPrice <= 5000000){
            $scope.snpLegalfee = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (5000000 - $scope.propertyPrice) * 0.005;
        }
        else if ($scope.propertyPrice <= 7500000){
            $scope.snpLegalfee = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (2000000) * 0.005 + (7500000 - $scope.propertyPrice) * 0.004;
        }
        else {
            $scope.snpLegalfee = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (2000000) * 0.005 + (2500000) * 0.04 + ($scope.propertyPrice - 7500000) * 0.004;
        }
      
        $scope.snpStampDuty = 0;
        if ($scope.propertyPrice < 100000) {
            $scope.snpStampDuty = $scope.propertyPrice * 0.01;
        }
        else if ($scope.propertyPrice < 500000) {
            $scope.snpStampDuty = 100000 * 0.01 + (500000 - $scope.propertyPrice) * 0.02;
        }
        else {
            $scope.snpStampDuty = 100000 * 0.01 + (400000) * 0.02 + ($scope.propertyPrice -500000)*0.03;
        }
        $scope.snpTotal = $scope.snpLegalfee + $scope.snpStampDuty;

        $scope.loanLegal = 0;
        if ($scope.propertyPrice <= 150000) {
            $scope.loanLegal = Math.max(0.01 * $scope.propertyPrice, 300);
        }
        else if ($scope.propertyPrice <= 1000000) {
            $scope.loanLegal = 150000 * 0.01 + ($scope.propertyPrice - 150000) * 0.007;
        }
        else if ($scope.propertyPrice <= 3000000) {
            $scope.loanLegal = 150000 * 0.01 + (850000) * 0.007 + (3000000 - $scope.propertyPrice) * 0.006;
        }
        else if ($scope.propertyPrice <= 5000000) {
            $scope.loanLegal = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (5000000 - $scope.propertyPrice) * 0.005;
        }
        else if ($scope.propertyPrice <= 7500000) {
            $scope.loanLegal = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (2000000) * 0.005 + (7500000 - $scope.propertyPrice) * 0.004;
        }
        else {
            $scope.loanLegal = 150000 * 0.01 + (850000) * 0.007 + (2000000) * 0.006 + (2000000) * 0.005 + (2500000) * 0.04 + ($scope.propertyPrice - 7500000) * 0.004;
        }
        $scope.loanStampDuty = $scope.propertyPrice * 0.005;
        $scope.loanTotal = $scope.loanLegal + $scope.loanStampDuty;

        $scope.total = $scope.loanTotal + $scope.snpTotal;



        
    }

    function validation() {
        $scope.warning = [];       
        if (!$scope.propertyPrice)
            $scope.warning.push({ msg: "Purchase price must not be empty!" })
       

    }
})